package com.cgtong.android.mvp.model;

import com.cgtong.android.http.ApiManager;
import com.cgtong.android.http.ConstantManager;
import com.cgtong.android.mvp.contract.RegisterContract;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.CallBackProxy;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.cookie.PersistentCookieStore;
import com.zhouyou.http.model.ApiResult;

import java.util.List;

import okhttp3.Cookie;

import static com.zhouyou.http.EasyHttp.getCookieJar;

/**
 * Created by Sky.Bing on 2017/10/23.
 */

public class RegisterModel implements RegisterContract.Model {

    @Override
    public void sendValidCode(String phone, String imgValidCode, SimpleCallBack<Object> callBack) {


        PersistentCookieStore cookieStore = getCookieJar().getCookieStore();
        List<Cookie> cookies = cookieStore.getCookies();
//        LogUtils.d("cookies == " + cookies.size());
//        for (Cookie c : cookies) {
//            LogUtils.d(c.name() + "  " + c.value());
//        }

        EasyHttp.post(ApiManager.URL_SEND_VALIDCODE)
                .params("mobile", phone)
                .params("code", imgValidCode)
                .addCookies(cookies)
                .params("codeType", ConstantManager.VALID_CODE_REGISTER)
                .execute(new CallBackProxy<ApiResult<Object>, Object>(callBack) {
                });
    }

    @Override
    public void doRegister(String phone, String mobileInfo, String validCode, String password, String confirmPassword, SimpleCallBack callBack) {
        EasyHttp.post(ApiManager.URL_REGISTER)
                .params("mobile", phone)
                .params("newPassword", password)
                .params("validCode", validCode)
                .params("confirmPassword", confirmPassword)
                .params("mobileInfo", mobileInfo)
                .execute(new CallBackProxy<ApiResult<Object>, Object>(callBack) {
                });
    }
}